#!/usr/bin/envpython
# -*-coding:UTF-8-*-
'''
@File    :   convert_help.py
@Contact :   308711822@qq.com
@License :   (C) Copyright 2021-2225, Personal exclusive right.

@Modify Time      @Author    @Version    @Desciption
------------      -------    --------    -----------
2023/5/27 13:34   小钟同学      1.0         None
'''


def convert_to_camel_case(s):
    return ''.join(word.capitalize() for word in s.split('_'))


def convert_dict_to_camel_case(d):
    # d = {
    #     'first_name': 'John',
    #     'last_name': 'Doe',
    #     'address': {
    #         'street_address': '123 Main St',
    #         'city': 'Anytown',
    #         'state': 'CA'
    #     },
    #     'phone_numbers': ['555-1234', '555-5678']
    # }
    #
    # new_dict = convert_dict_to_camel_case(d)
    # print(new_dict)
    new_dict = {}
    for key, value in d.items():
        if isinstance(value, dict):
            value = convert_dict_to_camel_case(value)
        elif isinstance(value, list):
            value = [convert_dict_to_camel_case(item) if isinstance(item, dict) else item for item in value]
        new_key = convert_to_camel_case(key)
        new_dict[new_key] = value
    return new_dict


def convert_to_camel_case_keepfirst(s):
    words = s.split('_')
    return words[0] + ''.join(word.capitalize() for word in words[1:])

def convert_dict_to_camel_case_keepfirst(d):
    new_dict = {}
    for key, value in d.items():
        if isinstance(value, dict):
            value = convert_to_camel_case_keepfirst(value)
        elif isinstance(value, list):
            value = [convert_to_camel_case_keepfirst(item) if isinstance(item, dict) else item for item in value]
        new_key = convert_to_camel_case_keepfirst(key)
        new_dict[new_key] = value
    return new_dict

# =========

from datetime import datetime

def convert_to_camel_case_forkeepfisrt_andtime(s):
    parts = s.split("_")
    return parts[0] + "".join(x.title() for x in parts[1:])

def convert_value(value):
    if isinstance(value, str):
        return convert_dict_to_camel_case_forkeepfisrt_andtime(value)
    elif isinstance(value, dict):
        return convert_dict_to_camel_case_forkeepfisrt_andtime(value)
    elif isinstance(value, bool) or isinstance(value, int):
        return bool(value)
    elif isinstance(value, datetime):
        return value.strftime("%Y-%m-%d %H:%M:%S")
    else:
        return value

def convert_dict_to_camel_case_forkeepfisrt_andtime(d):
    new_dict = {}
    for key, value in d.items():
        new_key = convert_to_camel_case(key)
        new_value = convert_value(value)
        new_dict[new_key] = new_value
    return new_dict
